package com.cn.aam.checaiduo.ui.more;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.cn.aam.checaiduo.R;
import com.cn.aam.checaiduo.backend.RetrofitHome;
import com.cn.aam.checaiduo.base.BaseActivity;
import com.cn.aam.checaiduo.base.ToolBarManager;
import com.cn.aam.checaiduo.base.adapter.BaseRecycerAdapter;
import com.cn.aam.checaiduo.bean.InfoOfDetailB;
import com.cn.aam.checaiduo.ui.arouter.UIRouter;
import com.cn.aam.checaiduo.ui.arouter.section.RouterMore;
import com.cn.aam.checaiduo.ui.more.adapter.FAQAdapter;
import com.cn.aam.checaiduo.ui.more.adapter.HelpCenterDetailAdapter;
import com.cn.aam.checaiduo.utils.MyViewsUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 具体帮助
 * 1.新手指南
 * 2.操作流程
 * 3.常见问题
 */
@Route(path = UIRouter.MORE.SUB_HELP_CENTER, name = "帮助中心子列表")
public class HelpCenterDetailIActivity extends BaseActivity {
    public final static String DATA_HELP_LESSON = "data_help_lesson";


    @BindView(R.id.id_recyclerview)
    RecyclerView mRecyclerView;

    private BaseRecycerAdapter<InfoOfDetailB> mAdapter;


    public enum LESSON implements Serializable {
        GUIDE, PROCEDURE, FAQ
    }

    private LESSON currentLesson = LESSON.GUIDE;


    @Override
    protected int layoutId() {
        return R.layout.activity_help_center_detail;
    }

    @Override
    protected void onGenerate() {
        currentLesson = (LESSON) getIntent().getSerializableExtra(DATA_HELP_LESSON);
        ToolBarManager toolbar = initPageView();

        switch (currentLesson) {
            case GUIDE:
                toolbar.setTitle("新手指南");
                mAdapter = new HelpCenterDetailAdapter(mContext);
                mRecyclerView.setAdapter(mAdapter);
                mAdapter.setDataToAdapter(getGuideData());
                break;
            case PROCEDURE:
                toolbar.setTitle("操作流程");
                mAdapter = new HelpCenterDetailAdapter(mContext);
                mRecyclerView.setAdapter(mAdapter);
                mAdapter.setDataToAdapter(getProcedureData());
                break;
            case FAQ:
                toolbar.setTitle("常见问题");
                mAdapter = new FAQAdapter(mContext);
                mRecyclerView.setAdapter(mAdapter);
                mAdapter.setDataToAdapter(getFaqData());
                break;
        }

        mAdapter.setOnItemClickListener(new BaseRecycerAdapter.OnItemClick() {
            @Override
            public void onClick(int position) {
                InfoOfDetailB item = mAdapter.getItem(position);
                actionDispatch(item.getValue());
            }
        });
    }

    private ToolBarManager initPageView() {
        //toolbar
        ToolBarManager toolbar = ToolBarManager.with(this, WMContent)
                .setBackgroundColor(R.color.toolbar_bg_grey)
                .setTitleColor(R.color.black_normal)
                .setNavigationIcon(R.drawable.ic_nav_arrow_back);
        //recy
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());//设置Item增加、移除动画
        return toolbar;
    }


    //新手指南
    private List<InfoOfDetailB> getGuideData() {
        List<InfoOfDetailB> list = new ArrayList<>();
        list.add(new InfoOfDetailB("各银行充值限额", "recharge"));
        list.add(new InfoOfDetailB("如何预约投资", "reserve"));
        list.add(new InfoOfDetailB("投资操作流程", "procedure"));
        return list;
    }


    //操作流程
    private List<InfoOfDetailB> getProcedureData() {
        List<InfoOfDetailB> list = new ArrayList<>();
        list.add(new InfoOfDetailB("如何更换手机号？", "changeMobile"));
        list.add(new InfoOfDetailB("如何更换银行卡？", "changeBankCard"));
        list.add(new InfoOfDetailB("提现须知", "withDraw"));
        return list;
    }

    //操作流程
    private List<InfoOfDetailB> getFaqData() {
        List<InfoOfDetailB> list = new ArrayList<>();
        list.add(new InfoOfDetailB(getString(R.string.help_faq_ask_01), getString(R.string.help_faq_answer_01)));
        list.add(new InfoOfDetailB(getString(R.string.help_faq_ask_02), getString(R.string.help_faq_answer_02)));
        list.add(new InfoOfDetailB(getString(R.string.help_faq_ask_03), getString(R.string.help_faq_answer_03)));
        list.add(new InfoOfDetailB(getString(R.string.help_faq_ask_04), getString(R.string.help_faq_answer_04)));
        list.add(new InfoOfDetailB(getString(R.string.help_faq_ask_05), getString(R.string.help_faq_answer_05)));
        return list;
    }

    /**
     * 操作分发
     *
     * @param action
     */
    public void actionDispatch(String action) {
        if (MyViewsUtils.isFastDoubleClick()) return;
        switch (action) {
            case "recharge":
                String url = RetrofitHome.HOST_API + "Wap/Usercenter/rechargeLimit.html";
                UIRouter.getInstance().getWeb().openWebPage(mContext, url, "限额说明");
                break;
            case "reserve":
                UIRouter.getInstance().getMore().openJustShowImagePage(mContext, JustShowImageActivity.ImgDispatch.Reserve);
                break;
            case "procedure":
                UIRouter.getInstance().getMore().openJustShowImagePage(mContext, JustShowImageActivity.ImgDispatch.Procedure);
                break;
            case "changeMobile":
                UIRouter.getInstance().getMore().openJustShowImagePage(mContext, JustShowImageActivity.ImgDispatch.ChangeMobile);
                break;
            case "changeBankCard":
                UIRouter.getInstance().getMore().openJustShowImagePage(mContext, JustShowImageActivity.ImgDispatch.ChangeBank);
                break;
            case "withDraw":
                UIRouter.getInstance().getMore().openJustShowImagePage(mContext, JustShowImageActivity.ImgDispatch.WithDraw);
                break;
        }
    }


}
